#import "CTControllerManager.h"
#import "CTTabbarController.h"
#import "CTNavigationController.h"
#import "CTHomeVC.h"
#import "CTGuideVC.h"
#import "CTLoginVC.h"
@implementation CTControllerManager
+(CTControllerManager *)ct_shareTabbarVC {
    static CTControllerManager * var_TabbarVC = nil;
    static dispatch_once_t var_onceToken;
    dispatch_once(&var_onceToken, ^{
        var_TabbarVC = [[CTControllerManager alloc]init];
    });
    return var_TabbarVC;
}
+ (void)ct_configRootVC {
    WeakSelf(weakSelf);
    CTGuideVC *guideVc = [[CTGuideVC alloc] init];
    guideVc.handleToHome = ^(void){
        if ([CTUserManager shareManager].hasLogined) {
            NSString *var_url = CTPath(@"", CTPathTypeWeb, nil);
            CTHomeVC *homeVC = [[CTHomeVC alloc] initWithTitle:@"" gotoUrl:var_url];
            [homeVC showRootVCStyle];
            CTNavigationController *aLoginNav = [[CTNavigationController alloc] initWithRootViewController:homeVC];
            [[UIApplication sharedApplication].delegate.window setRootViewController:aLoginNav];
        } else {
            BOOL isLaunchWeb = [[NSUserDefaults standardUserDefaults] boolForKey:kIsLaunchWeb];
            if (isLaunchWeb) {
                NSString *var_url = CTPath(@"", CTPathTypeWeb, nil);
                CTHomeVC *homeVC = [[CTHomeVC alloc] initWithTitle:@"" gotoUrl:var_url];
                [homeVC showRootVCStyle];
                CTNavigationController *aLoginNav = [[CTNavigationController alloc] initWithRootViewController:homeVC];
                [[UIApplication sharedApplication].delegate.window setRootViewController:aLoginNav];
            } else {
                CTUserModel *userModel = [CTUserManager shareManager].userModel;
                if (!beNil(userModel.wirelessDeviceNumber)) {
                    CTNavigationController *aEnterNav = [[CTNavigationController alloc] initWithRootViewController:[[NSClassFromString(@"CTEnterPwdVC") alloc] init]];
                    [[UIApplication sharedApplication].delegate.window setRootViewController:aEnterNav];
                } else {
                    CTNavigationController *aLoginNav = [[CTNavigationController alloc] initWithRootViewController:[[NSClassFromString(@"CTLoginVC") alloc] init]];
                    [[UIApplication sharedApplication].delegate.window setRootViewController:aLoginNav];
                }
            }
        }
    };
    [[UIApplication sharedApplication].delegate.window setRootViewController:guideVc];
}
+ (void)ct_switchRootVC:(BOOL)isSwitch
{
    CTUserModel *userModel = [CTUserManager shareManager].userModel;
    CTLoginVC *loginVC = [[CTLoginVC alloc] init];
    loginVC.phoneView.contentTF.text = isSwitch ? @"" : returnBeNil(userModel.wirelessDeviceNumber);
    CTNavigationController *rootNav = [[CTNavigationController alloc] initWithRootViewController:loginVC];
    [[UIApplication sharedApplication].delegate.window setRootViewController:rootNav];
}
+ (UIViewController *)ct_navWithController:(UIViewController *)vc
{
    CTNavigationController *var_nav = [[CTNavigationController alloc] initWithRootViewController:vc];
    return var_nav;
}
@end
